<%@ page import="com.webamc.common.enums.Fields" %>
<%@ page import="com.webamc.common.enums.Params" %>
<%@ page import="com.webamc.model.Customer" %>
<%@ page import="com.webamc.model.CustomerInfo" %>
<%@ page import="java.util.List" %>
<%@ page import="static com.webamc.util.CommonUtil.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%!
    static String href = "customer.html?action=view&" + Fields.CUSTOMERID + "=";
%>

<link rel="stylesheet" href="../webamc.css"/>
<div class="action-header">CUSTOMERS</div>
<%
    String target = request.getParameter(Params.POPUP); //this sent from Popup.jsp
    final boolean isPopup = null != target;
    final List<Customer> customers = (List) request.getAttribute(Params.BEAN);
    if (customers == null || customers.size() == 0) {
%><p class="header-divsmall">No Customer. <a href="customer.html?action=beforeCreate">click here</a> to create.</p>
<% return;
}
%>
<jsp:include page="msgs.jsp"/>

<table class="browse-table" border="1">
    <tr>
        <th>Customer Id</th>
        <th>Name</th>
        <th>Gender</th>
        <th>Category</th>
        <th>Status</th>
        <th>Address</th>
        <th>City</th>
        <th>State</th>
        <th>Contacts</th>
        <th>Mobile Number</th>
        <th>LastUpdated</th>
    </tr>

    <%
        boolean even = true;
        for (Customer u : customers) {
            CustomerInfo ui = u.getInfo(); //TODO:NPE?
            even = !even;
            String idHref;
            if (isPopup) {
                idHref = "javascript:parent.selectMe( '" + target + "'," + u.getCustomerId() + ")";
            } else {
                idHref = href + u.getCustomerId();
            }
    %>
    <tr class="<%=even?"rowone":"rowtwo"%>">
        <td><%=u.getCustomerId()%>
        </td>
        <td><a href="<%=idHref%>"><%=out(ui.getFullName())%>
        </a>
        </td>
        <td><%=out(ui.getGender())%>
        </td>
        <td><%=out(u.getCategory())%>
        </td>
        <td><%=out(u.getStatus())%>
        </td>
        <td><%=out(ui.getAddress())%>
        </td>
        <td><%=out(ui.getCity())%>
        </td>
        <td><%=out(ui.getState())%>
        </td>
        <td><%=out(ui.getContacts())%>
        </td>
        <td><%=out(ui.getMobile())%>
        </td>
        <td><%=getDateString(u.getLastUpdated())%>
        </td>
    </tr>
    <%}%>
</table>
